package cn.janyd.common.core.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

/**
 * @author janyd
 * @since 2020/8/17 21:30
 */
public enum UserTypeEnum {

    /**
     * 用户
     */
    USER(1, "用户"),

    /**
     * 管理员
     */
    ADMIN(2, "管理员");

    @EnumValue
    private final int value;

    private final String name;


    UserTypeEnum(int value, String name) {
        this.value = value;
        this.name = name;
    }

    @JsonValue
    public int getValue() {
        return value;
    }

    public String getName() {
        return name;
    }

    @JsonCreator
    public static UserTypeEnum parse(int value) {
        for (UserTypeEnum status : UserTypeEnum.values()) {
            if (status.getValue() == value) {
                return status;
            }
        }

        throw new RuntimeException("UserTypeEnum 序列化失败");
    }
}
